Arithmetic operators
w + Addition
w int sum = 4 + 7;
w - Subtraction
w float difference = 18.55 - 14.21;
w * Multiplication
w float product = 5 * 3.5;
w / Division
w int quotient = 14 / 3;
w % Modulo Reduction (Remainder from integer division)
w int remainder = 10 % 6;
w
NOTE: For integer arguments / and % correspond to the Pascal div and mod operators. Do not use ^ for computing powers – it denotes “bitwise XOR”.
*, / and % will be performed before + or - in any expression. Brackets can be used to force a different order of evaluation to this. Where division is performed between two integers, the result will be an integer, with remainder discarded. Modulo reduction is only meaningful between integers. If a program is ever required to divide a number by zero, this will cause an error, usually causing the program to crash.
The mod (%) is simply the remainder produced by dividing two integers. In the example shown in the table above, if we treat 10 / 6 as an integer divison, the quotient is 1 (rather than 1.666) and the remainder is 4. Hence, the variable remainder will get the value 4.